import http, { ApiResponse } from '../utils/request';

// 梦想列表接口
export interface Dreams {
  rows: DreamItem[];
  total: number;
}

// 梦想项接口
export interface DreamItem {
  id: string | number;
  title: string;
  content: string;
  status: number;
  createTime: string;
  updateTime: string;
  userId?: string | number;
  [key: string]: any;
}

// 梦想查询参数接口
export interface DreamParams {
  id?: number | string;
  status?: number;
  page?: number;
  pageSize?: number;
  userId?: string | number;
  [key: string]: any;
}

/**
 * 获取梦想大厅列表
 * @param params 查询参数
 * @returns Promise
 */
export const getDreamHall = (params: DreamParams): Promise<ApiResponse<Dreams>> => {
  return http.get<Dreams>('/dreams/hall', params);
};

/**
 * 获取我的梦想列表
 * @param params 查询参数
 * @returns Promise
 */
export const getMyDreams = (params: DreamParams): Promise<ApiResponse<Dreams>> => {
  return http.get<Dreams>('/dreams/my', params);
};

/**
 * 创建梦想
 * @param data 梦想数据
 * @returns Promise
 */
export const createDream = (data: Partial<DreamItem>): Promise<ApiResponse<DreamItem>> => {
  return http.post<DreamItem>('/dreams', data);
};

/**
 * 更新梦想
 * @param dream 梦想数据
 * @returns Promise
 */
export const updateDream = (dream: Partial<DreamItem>): Promise<ApiResponse<DreamItem>> => {
  return http.put<DreamItem>(`/dreams/${dream.id}`, dream);
};

/**
 * 删除梦想
 * @param id 梦想ID
 * @returns Promise
 */
export const deleteDream = (id: string | number): Promise<ApiResponse<any>> => {
  return http.delete<any>(`/dreams/${id}`);
};